if __name__ == '__main__':

    file = "D:\\combined.csv"
    file_iter = open(file, 'rU')
    
    distinctDoms = dict()    

    print 'Begin'
    for line in file_iter:
        line = line.strip().rstrip(',')
        eleme = line.split(',')
        for elem in eleme:
            if distinctDoms.has_key(elem):
                count = int(distinctDoms.get(elem))
                count += 1
                distinctDoms[elem] = count
            else:
                distinctDoms[elem] = 1

    list =  sorted(distinctDoms.items(), key=lambda x: x[1], reverse=True)
    
    f = open("D:\\distinct_doms.txt", 'w')
    for a, b in list:
        f.write(str(a) + ',' + str(b) + '\n')
    print len(list), 'items processed.'    
    print 'End'    

                
        
    
    